

#include 	"string.h"
#include 	"gpio.h"
#include 	"stm32h7xx_hal.h"
#include	"stdio.h"
#include 	"fatfs.h"

#if		PLAY_WAV_FILE	== 1
#include "sai.h"
#include "WM8960.h"
#include "Play_WAV.h"
#include "i2c.h"



uint16_t	g_sai_half_cnt = 0;
uint16_t	g_sai_cplt_cnt = 0;

uint8_t CloseFileFlag;    //1:already open file have to close it.

uint8_t EndFileFlag;      //1:reach the wave file end;
                          //2:wait for last transfer;
                          //3:finish transfer stop dma.

__IO uint8_t FillBufFlag; //0:fill first half buf;
                          //1:fill second half buf;
                          //0xFF:do nothing.

FIL WAV_File;             //File struct

wavctrl WaveCtrlData;     //Play control struct

uint32_t Audio_LastBytes; //The WAV file last bytes to play

#pragma pack(push)
#pragma pack(8)
uint8_t WAV_Buffer[WAV_BUFFER_SIZE*2] = {0};  //The buffer to ache WAV data
#pragma pack(pop)

int32_t WAV_OFFSET = 0;      //Offset of record FIL pointer in WAV file

int32_t WAV_LastData;    //The size last data to be played
uint8_t Play_Flag;        //When the WAV file is being play, Play_Flag = 1.

uint8_t Pause_Flag;       //When the player is pause, Pause_Flag = 1.

char Play_List[10][50] = {NULL}; //play list

uint8_t Music_Num_MAX;    //Number of music.

int8_t Music_Num = 0;    //the number of music which is being played.

uint8_t End_Flag;         //When the music is over, End_Flag = 1;

I2S_CallBack_Flag I2S_Flag; //I2S CallBack function flag.

#pragma pack(push)
#pragma pack(8)
//__align(8) uint8_t TempBuf[WAV_BUFFER_SIZE/2];
uint8_t TempBuf[WAV_BUFFER_SIZE/2];
//#pragma pack()		// 恢复默认对齐方式
#pragma pack(pop)		// 与#pragma pack(push) 成对使用


/**
  * @brief  Scan the WAV files that set the path.
  * @param  path: Path to scan.
  * @retval None
  */
FRESULT ScanWavefiles(char* path) {
  
  FRESULT res;
  FILINFO fno;
  DIR dir;
  uint16_t i,j;
  
  res = f_opendir(&dir, path);    //Open the directory
  if(res != FR_OK)  {
    printf("f_opendir error !\r\n");
    printf("fres=%d\r\n", res);
    return res;
  }
  
  for(i=0;;i++) {                 //Scan the files in the directory
    res = f_readdir(&dir, &fno);  //read a item
    if(res != FR_OK)  {
      printf("f_readdir error !\r\n");
      printf("fres=%d\r\n", res);
      return res;
    }
    if(fno.fname[0] == 0)         //scan to the end of the path
      break;
    
    for(j=0;j<_MAX_LFN;j++) {
      if(fno.fname[j] == '.')     //Check if the type of the file is WAV
      break;
    }
    
    if(((fno.fname[j+1] == 'w')||(fno.fname[j+1] == 'W'))
        &&((fno.fname[j+2] == 'a')||(fno.fname[j+2] == 'A'))
        &&((fno.fname[j+3] == 'v')||(fno.fname[j+3] == 'V'))) //The file is WAV
    {
      strcpy(Play_List[i], path);     //Copy type of file is WAV
      strcat(Play_List[i],"/");       // Add '/' to the buffer 
      strcat(Play_List[i],fno.fname); // Add file name to the buffer
      printf("%s\r\n", Play_List[i]); // print the whole file path to the UART
    }
  }
  res = f_closedir(&dir);             //Close the directory
  if(res != FR_OK)  {
    printf("f_closedir error !\r\n");
    return res;
  }
  
  Music_Num_MAX = i;
  
  printf("Scan WAV Files complete ! Music_Num = %d\r\n",Music_Num_MAX);
  
  return res;
}


/**
  * @brief  Play the WAV file that set the path.
  * @param  path: Path of the WAV file.
  * @retval None
  */
uint8_t PlayWaveFile(void)  {
  
  uint8_t res;
  
  CloseFileFlag = 0;
	EndFileFlag = 0;
	FillBufFlag = 0xFF;
  Play_Flag = 0;
  End_Flag = 0;
  I2S_Flag = I2S_No_CallBack;
  

  if(WAV_OFFSET != 0)
  {
	  return;
  }

  printf("Now Play: %s\r\n",Play_List[Music_Num]);
  Get_WAV_Message(Play_List[Music_Num],&WaveCtrlData);    //Get the messages of the WAV file
  
  WAV_OFFSET = WaveCtrlData.datastart;
  
  Play_Flag = 1;
  /*Start Play Music*/
  f_lseek(&WAV_File, WAV_OFFSET);
  Fill_WAV_Buffer(WAV_Buffer, WAV_BUFFER_SIZE);
  WAV_OFFSET += WAV_BUFFER_SIZE;
  WAV_LastData -= WAV_BUFFER_SIZE;

  if(Play_Flag == 1)
  {
	  HAL_SAI_Transmit_DMA(&hsai_BlockA3,WAV_Buffer, WAV_BUFFER_SIZE);
	  printf("HAL_SAI_Transmit_DMA(&hsai_BlockA3,WAV_Buffer, WAV_BUFFER_SIZE);\r\n");
  }

  while(End_Flag == 0)  {
    while(Play_Flag == 1) {
      if(I2S_Flag == I2S_Half_Callback) {

    	//HAL_SAI_Transmit_DMA(&hsai_BlockA3,(WAV_Buffer+WAV_BUFFER_SIZE/2),WAV_BUFFER_SIZE/2);
    	static uint32_t	half_tick_stamp = 0;
    	printf("I2S_Half_Callback: %d\r\n", g_sai_half_cnt);

    	half_tick_stamp = HAL_GetTick();
    	printf("Start half fill Tick():%d\r\n", half_tick_stamp);

        f_lseek(&WAV_File, WAV_OFFSET);
        Fill_WAV_Buffer(WAV_Buffer,WAV_BUFFER_SIZE);
        WAV_OFFSET += WAV_BUFFER_SIZE;
        WAV_LastData -= WAV_BUFFER_SIZE;
        printf("time of fill half(Ms):%d\r\n", HAL_GetTick() - half_tick_stamp);

        printf("WAV_OFFSET: %d\r\n", WAV_OFFSET);
//        printf("WAV_LastData: %d\r\n", WAV_LastData);
//        printf("File length: %d\r\n", WAV_LastData+WAV_OFFSET);
    
        I2S_Flag = I2S_No_CallBack;
      }
      if(I2S_Flag == I2S_Callback) {
    	  static uint32_t	cplt_tick_stamp = 0;
//    	HAL_SAI_Transmit_DMA(&hsai_BlockA3,WAV_Buffer, WAV_BUFFER_SIZE);
    	printf("I2S_Cplt_Callback: %d\r\n", g_sai_cplt_cnt);

    	cplt_tick_stamp = HAL_GetTick();
    	printf("Start cplt fill Tick():%d\r\n", cplt_tick_stamp);
        f_lseek(&WAV_File, WAV_OFFSET);
        Fill_WAV_Buffer((WAV_Buffer+WAV_BUFFER_SIZE),WAV_BUFFER_SIZE);
        WAV_OFFSET += WAV_BUFFER_SIZE;
        WAV_LastData -= WAV_BUFFER_SIZE;
        printf("time of fill cplt(Ms):%d\r\n", HAL_GetTick() - cplt_tick_stamp);

        printf("WAV_OFFSET: %d\r\n", WAV_OFFSET);
//        printf("WAV_LastData: %d\r\n", WAV_LastData);
//        printf("File length: %d\r\n", WAV_LastData+WAV_OFFSET);

        if(g_sai_cplt_cnt >= 100)
        {

        	End_Flag = 1;
        	printf("End_Flag = 1.\r\n", WAV_OFFSET);
        	HAL_SAI_DMAStop(&hsai_BlockA3);
        	break;
        }
    
        I2S_Flag = I2S_No_CallBack;
      }
      else  {
//        Key_Control();
      }
    }
  }
  
  res = f_close(&WAV_File);
  printf("f_close(&WAV_File)\r\n");
  
  return res;
}

/**
  * @brief  Open the WAV file, get the message of the file.
  * @param  fname: name of the file you want to get its massage.
  * @param  wavx: the struct of data control.
  * @retval None
  */
uint8_t Get_WAV_Message(char* fname, wavctrl* wavx) {
  
  uint8_t res = 0;
  uint32_t br = 0;
  
  ChunkRIFF *riff;
	ChunkFMT *fmt;
	ChunkFACT *fact;
	ChunkDATA *data;
  
  res = f_open(&WAV_File, (TCHAR *)fname, FA_READ);     //Open the file
  if(res == FR_OK) {
    
    CloseFileFlag = 1;
    
    f_read(&WAV_File, TempBuf, WAV_BUFFER_SIZE/2, &br); //Read WAV_BUFFER_SIZE/2 bytes data
    
    riff = (ChunkRIFF *)TempBuf;      //Get RIFF Chunk
    
    if(riff->Format == 0x45564157)  { //Format = "WAV"
      
      fmt = (ChunkFMT *)(TempBuf+12); //Get FMT Chunk
      if(fmt->AudioFormat==1||fmt->AudioFormat==3)        //Linear PCM or 32 bits WAVE
      {
        fact=(ChunkFACT *)(TempBuf+12+8+fmt->ChunkSize);  //Read FACT chunk
        
        if((fact->ChunkID == 0x74636166)||(fact->ChunkID==0X5453494C))
          wavx->datastart=12+8+fmt->ChunkSize+8+fact->ChunkSize;  //When there is fact/LIST Chunk.
        else
          wavx->datastart=12+8+fmt->ChunkSize;
        data = (ChunkDATA *)(TempBuf+wavx->datastart);
        if(data->ChunkID==0X61746164) {           //Read DATA Chunk success
          wavx->audioformat=fmt->AudioFormat;     //Audio Format
          wavx->nchannels=fmt->NumOfChannels;     //channel number
          wavx->samplerate=fmt->SampleRate;				//Sample Rate
          wavx->bitrate=fmt->ByteRate*8;					//Byte Rate
          wavx->blockalign=fmt->BlockAlign;				//Block Align
          wavx->bps=fmt->BitsPerSample;						//number of chunk, 8/16/24/32 bits
          wavx->datasize=data->ChunkSize;					//Size of audio data chunk
          wavx->datastart=wavx->datastart+8;			//data stream start offest
          printf("WAV.audioformat:%d\r\n",wavx->audioformat);
          printf("WAV.nchannels:%d\r\n",wavx->nchannels);
          printf("WAV.samplerate:%d\r\n",wavx->samplerate);
          printf("WAV.bitrate:%d\r\n",wavx->bitrate);
          printf("WAV.blockalign:%d\r\n",wavx->blockalign);
          printf("WAV.bps:%d\r\n",wavx->bps);
          printf("WAV.datasize:%d\r\n",wavx->datasize);
          printf("WAV.datastart:%d\r\n",wavx->datastart);  
        }
        else  {
          printf("Not find data chunk !!\r\n");
          printf("data->ChunkID = 0x%x\r\n",data->ChunkID);
          res = 4;
        }
      }
      else  {
        printf("Not linear PCM, not support !!\r\n");
        res = 3;
      }
    }
    else  {
      printf("Not WAV file !!\r\n");
      res = 2;
    }
  }
  else  {
    printf("Get_WAV_Message.f_open error! res:%ld\r\n", res);
    res = 1;
  }
  WAV_LastData = wavx->datasize;
  
  return res;
}

/**
  * @brief  Open the WAV file, get the message of the file.
  * @param  BUFF: the pointer of the buffer to cached data.
  * @param  size: the byte mumber of data.
  * @retval None
  */
uint32_t Fill_WAV_Buffer(uint8_t *BUFF, uint16_t size) {
  
  uint32_t NeedReadSize=0;
  uint32_t ReadSize;
  uint32_t i;
  uint8_t *p;
  float *f;
  int sound;
  
  //It has been read last time, return.
  if(EndFileFlag==1)
		return 0;
  
  if(WaveCtrlData.nchannels==2) {
    if(WaveCtrlData.bps == 16)          //16-bit audio,read data directly
    {
		f_read(&WAV_File,BUFF,size,(UINT*)&ReadSize);
    }
		else if(WaveCtrlData.bps==24)       //24-bit audio, adjust the order between the read data and the DMA cache
		{
			printf("WaveCtrlData.bps = %d\r\n",WaveCtrlData.bps);
			NeedReadSize=(size/4)*3;                                  //Number of bytes to read
			f_read(&WAV_File,TempBuf,NeedReadSize,(UINT*)&ReadSize);	//Read data
			p=TempBuf;
			ReadSize=(ReadSize/3)*4;                                  //Size of data after fill
			//printf("%d\r\n",ReadSize);
			for(i=0;i<ReadSize;)
			{
				BUFF[i]=p[1];
				BUFF[i+1]=p[2];
				BUFF[i+2]=0;
				BUFF[i+3]=p[0];
				i+=4;
				p+=3;
			}
		}
		else if(WaveCtrlData.bps == 8)      //8-bit audio, data need to be transformed to 16-bit mode before play
		{
			printf("WaveCtrlData.bps = %d\r\n",WaveCtrlData.bps);
			NeedReadSize=size/2;                                      //Number of bytes to read
			f_read(&WAV_File,TempBuf,NeedReadSize,(UINT*)&ReadSize);	//Read data
			p=TempBuf;
			ReadSize=ReadSize*2;                                      //Size of data after fill
			for(i=0;i<ReadSize;)
			{
				BUFF[i]=0;
				BUFF[i+1]=*p+0x80; 
				p++;
				i=i+2;
			} 	
		}
		else if(WaveCtrlData.bps == 32)     //32bit WAVE, floating-point numbers [(-1) ~ 1] to represent sound
		{
			printf("WaveCtrlData.bps = %d\r\n",WaveCtrlData.bps);
			f_read(&WAV_File,TempBuf,size,(UINT*)&ReadSize);					//Read data
			f=(float*)TempBuf;
			for(i=0;i<ReadSize;)
			{
				//printf("f=%f\r\n",*f);
				sound=0x7FFFFFFF*(*f);
				BUFF[i]=(uint8_t)(sound>>16);
				BUFF[i+1]=(uint8_t)(sound>>24);
				BUFF[i+2]=(uint8_t)(sound);
				BUFF[i+3]=(uint8_t)(sound>>8); 
				f++;
				i=i+4;
			} 						
		}
    else  {
      printf("WaveCtrlData.bps = %d\r\n",WaveCtrlData.bps);
      printf("Error !!\r\n");
    }
	}
	//Signal channel��adjust to dual channel data for playback
	else
	{
		if(WaveCtrlData.bps==16)
		{
			NeedReadSize=size/2;                                      //Number of bytes to read
			f_read(&WAV_File,TempBuf,NeedReadSize,(UINT*)&ReadSize);	//Read data
			p=TempBuf;
			ReadSize=ReadSize*2;                                      //Size of data after fill
			for(i=0;i<ReadSize;)
			{
				BUFF[i]=p[0];
				BUFF[i+1]=p[1];
				BUFF[i+2]=p[0];
				BUFF[i+3]=p[1];
				i+=4;
				p=p+2;
			}
		}
		else if(WaveCtrlData.bps==24)																	//24-bit audio
		{
			NeedReadSize=(size/8)*3;                                  //Number of bytes to read
			f_read(&WAV_File,TempBuf,NeedReadSize,(UINT*)&ReadSize);  //Read data
			p=TempBuf;
			ReadSize=(ReadSize/3)*8;                                  //Size of data after fill
			for(i=0;i<ReadSize;)
			{
				BUFF[i]=p[1];
				BUFF[i+1]=p[2]; 
				BUFF[i+2]=0;
				BUFF[i+3]=p[0];
				BUFF[i+4]=p[1];
				BUFF[i+5]=p[2];
				BUFF[i+6]=0;
				BUFF[i+7]=p[0];
				p+=3;
				i+=8;
			}
		}
		else if(WaveCtrlData.bps==8)                                //8-bit audio
		{
			NeedReadSize=size/4;                                      //Number of bytes to read
			f_read(&WAV_File,TempBuf,NeedReadSize,(UINT*)&ReadSize);  //Read data
			p=TempBuf;
			ReadSize=ReadSize*4;                                      //Size of data after fill
			for(i=0;i<ReadSize;)
			{
				BUFF[i]=0;
				BUFF[i+1]=*p+0x80; 
				BUFF[i+2]=0;
				BUFF[i+3]=*p+0x80;
				i+=4;
				p++;
			}
		}
		else                                                        //32-bit audio
		{
			NeedReadSize=size/2;                                      //Number of bytes to read
			f_read(&WAV_File,TempBuf,NeedReadSize,(UINT*)&ReadSize);	//Read data
			f=(float*)TempBuf;
			ReadSize=ReadSize*2;                                      //Size of data after fill
			for(i=0;i<ReadSize;)
			{
				sound=0x7FFFFFFF*(*f);
				BUFF[i+4] = BUFF[i]   = (uint8_t)(sound>>16);
				BUFF[i+5] = BUFF[i+1] = (uint8_t)(sound>>24);
				BUFF[i+6] = BUFF[i+2] = (uint8_t)(sound);
				BUFF[i+7] = BUFF[i+3] = (uint8_t)(sound>>8);
				f++;
				i=i+8;
      }
		}
	}
	if(ReadSize<size)   //Data is not enough, supplementary '0'
	{
		EndFileFlag=1;
		for(i=ReadSize;i<size-ReadSize;i++)
			BUFF[i] = 0;
	}
  f_sync(&WAV_File);
	return ReadSize;
}

/**
  * @brief  Check whether keys is pressed.
  * @param  None
  * @retval None
  */
void Key_Control(void)  {
//
//  //Start_Check
//  if(Key_Start_Check() == 1)  {
//    if(Pause_Flag == 0) {
//      HAL_SAI_DMAPause(&hsai_BlockB1);
//      printf("Pause!!\r\n");
//      Pause_Flag = 1;
//    }
//    else  {
//      HAL_SAI_DMAResume(&hsai_BlockB1);
//      printf("Resume!!\r\n");
//      Pause_Flag = 0;
//    }
//  }//Start_Check End
//  else if(Key_Next_Check() == 1)  {
//    printf("Next!\r\n");
//
//    Play_Flag = 0;
//    End_Flag = 1;
//
//    if(Pause_Flag == 1) {
//      Pause_Flag = 0;
//      HAL_SAI_DMAStop(&hsai_BlockB1);
//    }
//  }
//  else if(Key_Last_Check() == 1)  {
//    printf("Last!\r\n");
//
//    Music_Num -= 2;
//    if(Music_Num < 0)
//      Music_Num += Music_Num_MAX;
//
//    Play_Flag = 0;
//    End_Flag = 1;
//
//    if(Pause_Flag == 1) {
//      HAL_SAI_DMAStop(&hsai_BlockB1);
//      Pause_Flag = 0;
//    }
//  }
}

void	read_file_wav_test(void)
{
	ScanWavefiles("0:/wavPlay");
	printf("Now Read file: %s\r\n",Play_List[Music_Num]);

	Get_WAV_Message(Play_List[Music_Num],&WaveCtrlData);    //Get the messages of the WAV file

	f_lseek(&WAV_File, 44);
	Fill_WAV_Buffer(WAV_Buffer,WAV_BUFFER_SIZE);

	{
		int32_t idx = 0;
		for(idx=0;idx<100;idx+=1)
		{
			printf("%3x", WAV_Buffer[idx]);
			if((idx+1)%16==0)
			{
				printf("\r\n");
			}
		}
	}
}

#endif

FIL MyFile;     /* File object */
int rest = 500;


#define		RW_Buff_Len 	4096

void SDIO_FatFs_Test(void)
{

	int i = 0;
	uint32_t	ms_stamp = 0;
	uint32_t	ms_span = 0;




  FRESULT res;                                          		/* FatFs function common result code */
  uint32_t byteswritten, bytesread;                     		/* File write/read counts */
  //uint8_t wtext[] = "This is STM32H750 working with FatFs"; 	/* File write buffer */
  uint8_t wtext[RW_Buff_Len];
  TCHAR* fname = "STM32H750VBT6_Brd_20201130.TXT"; 						/* File Name */
  uint8_t rtext[RW_Buff_Len];                                   		/* File read buffer */

  for(i=0;i<RW_Buff_Len;i++)
  {
	  wtext[i] = 'a'+i%26;
  }


  if(f_mount(&SDFatFS, (TCHAR const*)SDPath, 0) != FR_OK)
	{
		/* FatFs Initialization Error */
	  printf("f_mount Error.\r\n");
		Error_Handler();
	}
	else
	{
		printf("f_mount OK.\r\n");
		/*##-4- Create and Open a new text file object with write access #####*/
		if(f_open(&MyFile, fname, FA_CREATE_ALWAYS | FA_WRITE) != FR_OK)
		{
			printf("f_open Error.\r\n");
			Error_Handler();
		}
		else
		{
			printf("f_open OK.\r\n");

//			ms_stamp = HAL_GetTick();
//			for(i=0;i<20;i++)
//			{
//				res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread);
//				if((byteswritten == 0) || (res != FR_OK))
//				{
//					printf("f_read Error: %d\r\n", i);
//					Error_Handler();
//					break;
//				}
//			}
//			ms_span = HAL_GetTick() - ms_stamp;
//
//			if(ms_span > 0)
//			{
//				printf("Read 20*4096 Bytes in %d Ms.\r\n", ms_span);
//				printf("Read Speed: %d KByte/S\r\n", 20*4096/ms_span);
//			}


			/*##-5- Write data to the text file ################################*/
			ms_stamp = HAL_GetTick();
			for(i=0;i<20;i++)
			{
				res = f_write(&MyFile, wtext, sizeof(wtext), (void *)&byteswritten);

				if((byteswritten == 0) || (res != FR_OK))
				{
					printf("f_write Error: %d\r\n", i);
					Error_Handler();
					break;
				}
				res = f_sync(&MyFile);
				if(res != FR_OK)
				{
					printf("f_sync Error:%d\r\n", res);
					Error_Handler();
				}
			}
			ms_span = HAL_GetTick() - ms_stamp;
			if(ms_span > 0)
			{
				printf("Write 20*4096 Bytes in %d Ms.\r\n", ms_span);
				printf("Write Speed: %d KByte/S\r\n", 20*4096/ms_span);
			}

//			printf("byteswritten:%d, res:%d\r\n", byteswritten, res);

			if((byteswritten == 0) || (res != FR_OK))
			{
				printf("f_write Error.\r\n");
				Error_Handler();
			}
			else
			{
				/*##-6- Close the open text file #################################*/
//				HAL_Delay(150);
				res = f_close(&MyFile);
				HAL_Delay(100);
				if(res != FR_OK)
				{
					printf("f_close Error:%d\r\n", res);
					Error_Handler();
				}

				/*##-7- Open the text file object with read access ###############*/
				if(f_open(&MyFile, fname, FA_READ) != FR_OK)
				{
					printf("f_open Error 2.\r\n");
					Error_Handler();
				}
				else
				{
					/*##-8- Read data from the text file ###########################*/
//					res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread);

					ms_stamp = HAL_GetTick();
					for(i=0;i<20;i++)
					{
						res = f_read(&MyFile, rtext, sizeof(rtext), (UINT*)&bytesread);
						if((byteswritten == 0) || (res != FR_OK))
						{
							printf("f_write Error: %d\r\n", i);
							Error_Handler();
							break;
						}
					}
					ms_span = HAL_GetTick() - ms_stamp;

					if(ms_span > 0)
					{
						printf("Read 20*4096 Bytes in %d Ms.\r\n", ms_span);
						printf("Read Speed: %d KByte/S\r\n", 20*4096/ms_span);
					}

					if((bytesread == 0) || (res != FR_OK)) /* EOF or Error */
					{
						printf("f_read Error 2\r\n");
						Error_Handler();
					}
					else
					{
						/*##-9- Close the open text file #############################*/
						//f_close(&MyFile);
						if(f_close(&MyFile) != FR_OK)
						{
							printf("f_close Error.\r\n");
							Error_Handler();
						}

						/*##-10- Compare read data with the expected data ############*/
						if ((bytesread != byteswritten))
						{
							/* Read data is different from the expected data */
							printf("Read data is different from the write data.\r\n");
							printf("The SDMMC fatfs read and write demo Failed XXX!\r\n");
							Error_Handler();
						}
						else
						{
							/* Success of the demo: no error occurrence */
							printf("Read data is same from the write data.\r\n");
							printf("The SDMMC fatfs read and write demo is Successful.\r\n");
							// BSP_LED_On(LED1);

							rest = 1000;
						}
					}
				}
			}
		}
	}
}



